package net.rong.mobileim;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import net.x52im.mobileimsdk.android.event.ChatBaseEvent;
import net.x52im.mobileimsdk.server.protocal.s.PKickoutInfo;

public class ChatBaseEventListener implements ChatBaseEvent {

    private final ReactApplicationContext reactContext;

    public ChatBaseEventListener(ReactApplicationContext reactContext) {
        this.reactContext = reactContext;
    }

    @Override
    public void onLoginResponse(int code) {
        WritableMap params = Arguments.createMap();
        params.putInt("code", code);

        reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(EventConst.ON_LOGIN_RESPONSE, params);
    }

    @Override
    public void onLinkClose(int code) {
        WritableMap params = Arguments.createMap();
        params.putInt("code", code);

        reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(EventConst.ON_LINK_CLOSE, params);
    }

    @Override
    public void onKickout(PKickoutInfo pKickoutInfo) {
        WritableMap params = Arguments.createMap();
        params.putInt("code", pKickoutInfo.getCode());

        reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(EventConst.ON_KICK_OUT, params);
    }

}
